//
//  ViewController.swift
//  test
//
//  Created by myd on 15/12/23.
//  Copyright © 2015年 myd1. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
                demo2()
        // Do any additional setup after loading the view, typically from a nib.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

        // Dispose of any resources that can be recreated.
    }


    func demo2()
    {
        let  aa : dispatch_group_t = dispatch_group_create()
        let  bb : dispatch_queue_t = dispatch_queue_create("myd", DISPATCH_QUEUE_SERIAL)
        dispatch_group_enter(aa)
        print("进入了一组")
        dispatch_async(bb) { () -> Void in
            NSThread.sleepForTimeInterval(2)
                     print("离开了一组")
            dispatch_group_leave(aa)
   
        }
        dispatch_group_enter(aa)
        print("进入了二组")
        dispatch_async(bb) { () -> Void in
             NSThread.sleepForTimeInterval(2)
                 print("离开了二组")
            dispatch_group_leave(aa)
       
        }
        dispatch_group_notify(aa, bb) { () -> Void in
            print("所有人物任务执行完毕")
        }
        print("所有任务完毕")
    }
    
    func demo()
    {
        
        let aa : dispatch_group_t = dispatch_group_create()
        let bb : dispatch_queue_t = dispatch_queue_create("myd", DISPATCH_QUEUE_SERIAL)
        dispatch_async(bb) { () -> Void in
            print("任务一完成")
        }
        dispatch_async(bb) { () -> Void in
            print("任务二完成")
        }
   dispatch_group_notify(aa, bb) { () -> Void in
    print("所有任务完成")
        }
        print("aaa")
    }
}

